package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.DeviceAlarmNotificationPageListReqDTO;
import com.huaxin.device.dto.response.GetDeviceAlarmNotificationsByElectricianIdRespDTO;
import com.huaxin.device.models.DeviceAlarmNotification;
import com.huaxin.device.service.DeviceAlarmNotificationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "设备报警信息通知")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/deviceAlarmNotification")
public class DeviceAlarmNotificationController {
    private final DeviceAlarmNotificationService service;

    @GetMapping("/getByNotificationId")
    @Operation(summary = "获取设备报警通知", description = "获取设备报警通知")
    public ResponseResult<DeviceAlarmNotification> getByNotificationId(@Parameter(description = "设备报警通知ID", required = true, name = "id") @RequestParam(name = "id", required = true) String id) {
        DeviceAlarmNotification deviceAlarmNotification = service.getByNotificationId(id);
        return ResponseResult.ok(deviceAlarmNotification);
    }

    @PostMapping("/pageQuery")
    @Operation(summary = "分页查询设备报警通知", description = "分页查询设备报警通知")
    public ResponseResult<IPage<DeviceAlarmNotification>> pageQuery(@RequestBody @Valid DeviceAlarmNotificationPageListReqDTO in) {
        return service.pageQuery(in);
    }

    @GetMapping("/read")
    @Operation(summary = "读取设备报警通知", description = "读取设备报警通知")
    public ResponseResult<Boolean> read(@Parameter(description = "设备报警通知ID", required = true, name = "id") @RequestParam(name = "id", required = true) String id) {
        return service.read(id);
    }

    //根据电工id获取所关联的所有企业的设备预警通知
    @GetMapping("/getDeviceAlarmNotificationsByElectricianId")
    @Operation(summary = "根据电工id获取所关联的所有企业的设备预警通知", description = "根据电工id获取所关联的所有企业的设备预警通知")
    public ResponseResult<List<GetDeviceAlarmNotificationsByElectricianIdRespDTO>> getDeviceAlarmNotificationsByElectricianId(@Parameter(description = "电工id", required = true, name = "electricianId") @RequestParam(name = "electricianId", required = true) String electricianId) {
        return service.getDeviceAlarmNotificationsByElectricianId(electricianId);
    }

    //根据企业id查询设备报警通知数量
    @GetMapping("/queryDeviceAlarmNotificationCountByOrgId")
    @Operation(summary = "根据企业id查询设备报警通知数量", description = "根据企业id查询设备报警通知数量")
    public ResponseResult<Long> queryDeviceAlarmNotificationCountByOrgId(@Parameter(description = "企业id", required = true, name = "orgId") @RequestParam(name = "orgId", required = true) String orgId) {
        return service.queryDeviceAlarmNotificationCountByOrgId(orgId);
    }
}
